#include "stdafx.h"

#include "Animation.h"

namespace ETM
{
	Animation::Animation()
	{
		
	}

	Animation::Animation(int frames, float timePerFrame, int offsetX, int offsetY, int frameW, int frameH)
	{
		this->timePerFrame = timePerFrame;
		this->currentFrame = 0;
		this->timer = 0.0f;

		for(int i = 0; i < frames; i++)
		{
			int x = i * offsetX;
			int y = i * offsetY;
			this->frames.push_back(sf::IntRect(x, y, x + frameW, y + frameH));
		}
	}

	void Animation::Update(float delta)
	{
		timer += delta;

		if(timer >= timePerFrame)
		{
			currentFrame++;

			if(currentFrame >= (int)frames.size())
			{
				currentFrame = 0;
			}

			timer = 0.0f;
		}
	}

	sf::IntRect Animation::GetRect()
	{
		return frames.at(currentFrame);
	}
}